package com.skit.jetpackstudy.livedata

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import com.skit.jetpackstudy.R
import kotlinx.android.synthetic.main.live_data_activity.*

class LiveDataActivity : AppCompatActivity() {
    private lateinit var viewModelWithLiveData: ViewModelWithLiveData
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.live_data_activity)
        viewModelWithLiveData = ViewModelProviders.of(this).get(ViewModelWithLiveData::class.java)
        viewModelWithLiveData.number.observe(this, Observer<Int> { i ->
            tv.text = i.toString()
        })
        button.setOnClickListener { v -> viewModelWithLiveData.addNumber(1) }
        button2.setOnClickListener { v -> viewModelWithLiveData.addNumber(-1) }
    }
}
